#ifndef KVCFG_H_
#define KVCFG_H_
#include "conf.h"

C_CODE_BEGIN
#include <stdio.h>

struct kv_element;

enum kv_type{
	KV_ATOM,
	KV_COLLECTION
};

// creation routine
EXPORT_FUNC struct kv_element* kv_element_create( enum kv_type , const char* name );
EXPORT_FUNC void kv_element_destroy( struct kv_element* );
EXPORT_FUNC struct kv_element* kv_element_index( struct kv_element* , int  );
EXPORT_FUNC struct kv_element* kv_element_query( struct kv_element* , const char* );

// insert
EXPORT_FUNC bool kv_element_push_back( struct kv_element* ,struct kv_element* );
EXPORT_FUNC bool kv_element_insert( struct kv_element* , const char* , struct kv_element* );
EXPORT_FUNC bool kv_element_set_atomic_value( struct kv_element* , const char* );

// remove
EXPORT_FUNC void kv_element_kv_remove( struct kv_element* , const char* k );
EXPORT_FUNC void kv_element_pop_back ( struct kv_element* );

//foreach
EXPORT_FUNC void kv_element_kv_foreach( struct kv_element* , bool (*func_t)(const char* k,struct kv_element*v,void* arg) , void* arg );
EXPORT_FUNC void kv_element_ls_foreach( struct kv_element* , bool (*func_t)(int idx,struct kv_element*v,void* arg),void* arg);

//accessor
EXPORT_FUNC const char* kv_element_get_key( struct kv_element* );
EXPORT_FUNC const char* kv_element_get_atomic_value( struct kv_element* );
EXPORT_FUNC enum kv_type kv_element_get_type( struct kv_element* );

//script parser
EXPORT_FUNC struct kv_element* kv_element_load_script( const char* );
EXPORT_FUNC struct kv_element* kv_element_load_buffer( const char* );

//printer 
EXPORT_FUNC void kv_element_print( FILE* , struct kv_element* );

C_CODE_END
#endif // KVCFG_H_